// StudyTitlebar.cpp : implementation file
//

#include "stdafx.h"
#include "Taurus_Viewer/StudyTitlebar.h"
#include "Taurus_Common/Monitor.h"
#include "Taurus_Viewer/StudyViewStyle.h"
#include "Taurus_Viewer/StudyView.h"
#include "Taurus_Viewer/MonitorWnd.h"
#include "Taurus_Viewer/resource.h"

// CStudyTitlebar

IMPLEMENT_DYNAMIC(CStudyTitlebar, CWnd)

CStudyTitlebar::CStudyTitlebar()
{

}

CStudyTitlebar::~CStudyTitlebar()
{
}

void CStudyTitlebar::arrangeControls()
{
  CStudyView* view = static_cast<CStudyView*>(GetParent());
  const CMonitorWnd* monitorWnd = view->getMonitorWnd();
  if(monitorWnd == NULL) return;

  CRect client;
  GetClientRect(&client);

  CPoint pt = client.TopLeft();

  MonitorResolutionType resType = monitorWnd->getMonitor()->getResolutionType();
  CRect margin = CStudyViewStyle::getTitleBarBtnMargin(resType);

  CSize btnSize = CStudyViewStyle::getOpenStudyListBtnSize(resType);
  CRect rcBtn = client;
  rcBtn.left = pt.x;
  rcBtn.right = pt.x += (margin.left + btnSize.cx + margin.right);
  rcBtn.bottom = pt.y + margin.top + btnSize.cy + margin.bottom;
  rcBtn.DeflateRect(margin.left, margin.top, margin.right, margin.bottom);
  m_theOStudyListBtn.MoveWindow(&rcBtn, FALSE);

  btnSize = CStudyViewStyle::getSeriesViewLayoutComboSize(resType);
  rcBtn = client;
  rcBtn.left = pt.x;
  rcBtn.right = pt.x += (margin.left + btnSize.cx + margin.right);
  rcBtn.bottom = pt.y + margin.top + btnSize.cy + margin.bottom;
  rcBtn.DeflateRect(margin.left, margin.top, margin.right, margin.bottom);
  m_theSeriesViewCombo.MoveWindow(&rcBtn, FALSE);
  m_theSeriesViewCombo.SetItemHeight(0, rcBtn.Height() - 6);
  m_theSeriesViewCombo.SetItemHeight(-1, rcBtn.Height() - 6);

  btnSize = CStudyViewStyle::getCloseStudyBtnSize(resType);
  rcBtn = client;
  rcBtn.right -= margin.right;
  rcBtn.left = rcBtn.right - btnSize.cx;
  rcBtn.top += margin.top;
  rcBtn.bottom = rcBtn.top + btnSize.cy;
  m_theCloseButton.MoveWindow(&rcBtn, FALSE);
}

BEGIN_MESSAGE_MAP(CStudyTitlebar, CWnd)
  ON_WM_CREATE()
  ON_WM_SIZE()
  ON_WM_PAINT()
  ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

// CStudyTitlebar message handlers
int CStudyTitlebar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if(CWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

  m_theOStudyListBtn.Create(NULL, WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_CENTER, CRect(0, 0, 0, 0), this, IDC_STUDY_TITLEBAR_BTN_OPEN_STUDY_LIST);

  m_theSeriesViewCombo.Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS, CRect(0, 0, 0, 0), this, IDC_STUDY_TITLBE_BAR_CMB_SERIES_VIEW_LAYOUT);

  m_theCloseButton.Create(_T("X"), WS_CHILD | WS_VISIBLE | BS_VCENTER | BS_CENTER, CRect(0, 0, 0, 0), this, IDC_STUDY_TITLEBAR_BTN_CLOSE);
  return 0;
}

void CStudyTitlebar::OnSize(UINT nType, int cx, int cy)
{
  CWnd::OnSize(nType, cx, cy);

  if(cx > 0 && cy > 0)
    arrangeControls();
}

void CStudyTitlebar::OnPaint()
{
  CPaintDC dc(this);

  CRect client;
  GetClientRect(&client);
  COLORREF oldClr = dc.SetTextColor(m_theTextColor);
  dc.DrawText(_T("No Exams"), -1, &client, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
  dc.SetTextColor(oldClr);
}

BOOL CStudyTitlebar::OnEraseBkgnd(CDC* pDC)
{
  CRect client;
  GetClientRect(&client);

  pDC->FillSolidRect(&client, m_theBKColor);
  return TRUE;
}